#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    char kw[26],c;
    int s[26]={0},key[26],len,i;
    cin>>kw;
    len=strlen(kw);
    for(i=0;i<len;i++)
    {
        if(kw[i]>='a')
        {
            s[kw[i]-'a']=1; key[i]=kw[i]-'a';
        }
        else
        {
            s[kw[i]-'A']=1; key[i]=kw[i]-'A';
        }
    }
    for(i=25;i>=0;i--)
    if(s[i]==0) key[len++]=i;
    for(i=0;i<26;i++) s[key[i]]=i;
    //for(i=0;i<26;i++) { c=s[i]+'A'; cout<<c;}
    getchar();
    while((c=getchar())!=EOF)
    {
        if(c>='a' && c<='z') c=s[c-'a']+'a';
        else if(c>='A' && c<='Z') c=s[c-'A']+'A';
        cout<<c;
    }

    return 0;
}
